﻿
Imports std

Public Module amutest

    Public Sub unhandledException(ByVal ex As Exception)
        finishmain()
    End Sub

    Public Sub main(ByVal args() As String)
        If args Is Nothing OrElse args.Length() = 0 Then
            raiseError("should have at lease one collection to do amutest.", errorHandle.errorType.warning)
            raiseError("existing amutest collections, " + _
                       "base std stdperf cacheManager remotecallperf " + _
                       "httpServer2 valueIntervalPerf freclust freclustperf duallock, " _
                       + "all for all existing tests." _
                       , errorHandle.errorType.warning)
        Else
            startmain(AddressOf unhandledException, errorHandle.NOLOGFILEMARK)
            counter.initial(counter.NOCOUNTERFILEMARK)

            'break debugmode in release folder
            If strsame(envs.executingDirectory(), "release", False) Then
                setnormalmode()
            End If
            If Not isdebugmode() Then
                errorHandle.skipErrorType += errorHandle.errorTypeChar(errorHandle.errorType.information)
                setdebugmode()
            Else
                setstrongassert()
                setperformanceCheck()
            End If

            Dim i As Int64
            For i = 0 To args.Length() - 1
                If strsame(args(i), "base", False) Then
                    baseTests()
                ElseIf strsame(args(i), "std", False) Then
                    stdTests()
                ElseIf strsame(args(i), "cacheManager", False) Then
                    cacheManagerTests()
                ElseIf strsame(args(i), "cacheManager2", False) Then
                    cacheManager2Tests()
                ElseIf strsame(args(i), "stdperf", False) Then
                    stdPerfTests()
                ElseIf strsame(args(i), "remotecallperf", False) Then
                    remotecallPerfTests()
                ElseIf strsame(args(i), "list", False) Then
                    list(Of String).automaticalUnittest()
                ElseIf strsame(args(i), "map", False) Then
                    map(Of String, String).automaticalUnittest()
                ElseIf strsame(args(i), "mapperf", False) Then
                    map(Of String, String).performanceTest()
                ElseIf strsame(args(i), "set", False) Then
                    [set](Of String).automaticalUnittest()
                ElseIf strsame(args(i), "setperf", False) Then
                    [set](Of String).performanceTest()
                ElseIf strsame(args(i), "setperf2", False) Then
                    [set](Of String).performanceTest2()
                ElseIf strsame(args(i), "list", False) Then
                    list(Of String).automaticalUnittest()
                ElseIf strsame(args(i), "vector", False) Then
                    vector(Of String).automaticUnittest()
                ElseIf strsame(args(i), "sequentialLock", False) Then
                    sequentialLock.automaticalUnittest()
                ElseIf strsame(args(i), "vectorperf", False) Then
                    vector(Of String).performanceTest()
                ElseIf strsame(args(i), "heap", False) Then
                    heap(Of String).automaticalUnittest()
                ElseIf strsame(args(i), "trie", False) Then
                    chartrie(Of Int32).automaticalUnittest()
                ElseIf strsame(args(i), "httpServer2", False) Then
                    httpServer2()
                ElseIf strsame(args(i), "valueIntervalPerf", False) Then
                    valueIntervalPerfTest()
                ElseIf strsame(args(i), "freclust", False) Then
                    freclustTests()
                ElseIf strsame(args(i), "freclustperf", False) Then
                    freclustPerf()
                ElseIf strsame(args(i), "duallock", False) Then
                    duallockTests()
                ElseIf strsame(args(i), "all", False) Then
                    baseTests()
                    stdTests()
                    stdPerfTests()
                    cacheManagerTests()
                    cacheManager2Tests()
                    remotecallPerfTests()
                    freclustTests()
                    freclustPerf()
                    duallockTests()
                    Exit For
                Else
                    raiseError("invalid amutest collection " + args(i), errorHandle.errorType.warning)
                End If
                If consoleExtSignal() Then
                    Exit For
                End If
            Next

            finishmain()
        End If
    End Sub

    Private Sub baseTests()
        bytes.automaticalUnittest()
        'release bytes, < 00:01
        sequentialLock.automaticalUnittest()
    End Sub

    Private Sub stdTests()
        vector(Of String).automaticUnittest()
        'release vector, ~17:30
        list(Of String).automaticalUnittest()
        'release deque, ~02:00
        [set](Of String).automaticalUnittest()
        'release set, ~01:15
        map(Of String, String).automaticalUnittest()
        'release map, ~01:11
        heap(Of String).automaticalUnittest()
        'release heap, ~01:20
        mapheap(Of String, String).automaticalUnittest()
        'release mapheap, ~01:28? origin ~02:05:00
        chartrie(Of Int32).automaticalUnittest()
    End Sub

    Private Sub stdPerfTests()
        vector(Of String).performanceTest()
        'release vector, ~13:00
        [set](Of String).performanceTest()
        'release set, ~13:30
        [set](Of String).performanceTest2()
        'release set, ~00:10? origin 03:00
        map(Of String, String).performanceTest()
        'release map, ~14:00
    End Sub

    Private Sub cacheManagerTests()
        cacheManager(Of String, String).automaticalUnittest()
        'release cacheManager, ~45:00
    End Sub

    Private Sub cacheManager2Tests()
        cacheManager2(Of String, String).automaticalUnittest()
    End Sub

    Private Sub remotecallPerfTests()
        Dim thread As Threading.Thread = Nothing
        thread = startThread(AddressOf remotecall.rcserve.unittest)

        remotecall.rcclient.performanceTest()
        'release remotecallperf, ~03:30

        thread.Abort()
    End Sub

    Private Sub httpServer2()
        httpServer2Tests.amutest.start()
    End Sub

    Private Sub valueIntervalPerfTest()
        valueInterval.performanceTest()
        'debug ~30s
    End Sub

    Private Sub freclustTests()
        freclust.unittest.fceslite.go()
    End Sub

    Private Sub freclustPerf()
        freclust.perftest.fceslite.go()
    End Sub

    Private Sub duallockTests()
        duallock.unittest()
    End Sub

End Module
